{{ define "main" }}

{{ partial "page-title.html" . }}

<div class="page-wrapper">
  <div class="container">
    <div class="row">
      <div class="col-md-8">
        {{ $paginator := .Paginate .Data.Pages }}
        {{ range $paginator.Pages }}
        <div class="post">
          <div class="post-media post-thumb">
            <a href="{{ .Permalink }}">
              <img src="{{ .Params.Image | relURL }}" alt="{{ .Title }}">
            </a>
          </div>
          <h3 class="post-title"><a href="{{ .Permalink }}">{{ .Title }}</a></h3>
          <div class="post-meta">
            <ul>
              <li><i class="ion-calendar"></i> {{ .PublishDate.Format "January 2, 2006" }}</li>
              <li><i class="ion-android-people"></i>
                {{ i18n "posted_by" }}
                {{if site.Params.multi_author}}
                {{ range $index, $elements:= .Params.Author }}{{ if ne $index 0 }}, {{ end }}<a class="text-primary" href="{{ `author/` | relLangURL }}{{ . | urlize }}">{{ . }}</a>{{ end }}
                {{else}}
                <a class="text-primary" href="{{ `author/` | relLangURL }}{{ .Params.Author | urlize }}">{{ .Params.Author }}</a>
                {{end}}
              </li>
              <li><i class="ion-pricetags"></i> 
                {{ range $index, $elements:= .Params.Tags }}
                {{ if ne $index 0 }}, {{ end }}<a href="{{ `tags/` | relLangURL }}{{ . | lower }}">{{ . | humanize }}</a>
								{{ end }}
              </li>
            </ul>
          </div>
          <div class="post-content">
            <p>{{ .Summary }}</p>
            <a href="{{ .Permalink }}" class="btn btn-main">{{ i18n "read_more" }}</a>
          </div>
        </div>
        {{ end }}
        
				<!-- pagination -->
				{{ $paginator := .Paginator }}
				{{ $adjacent_links := 2 }}
				{{ $max_links := (add (mul $adjacent_links 2) 1) }}
				{{ $lower_limit := (add $adjacent_links 1) }}
				{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
				{{ if gt $paginator.TotalPages 1 }}
				<nav class="text-center">
					<ul class="pagination post-pagination">
						<!-- Previous page. -->
						{{ if $paginator.HasPrev }}
						<li>
							<a href="{{ $paginator.Prev.URL }}" class="page-link">{{ i18n "page_prev" }}</a>
            </li>
            {{ end }}
						<!-- Page numbers. -->
						{{ range $paginator.Pagers }}
						{{ $.Scratch.Set "page_number_flag" false }}
						<!-- Advanced page numbers. -->
						{{ if gt $paginator.TotalPages $max_links }}
						<!-- Lower limit pages. -->
						<!-- If the user is on a page which is in the lower limit.  -->
						{{ if le $paginator.PageNumber $lower_limit }}
						<!-- If the current loop page is less than max_links. -->
						{{ if le .PageNumber $max_links }}
						{{ $.Scratch.Set "page_number_flag" true }}
						{{ end }}
						<!-- Upper limit pages. -->
						<!-- If the user is on a page which is in the upper limit. -->
						{{ else if ge $paginator.PageNumber $upper_limit }}
						<!-- If the current loop page is greater than total pages minus $max_links -->
						{{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
						{{ $.Scratch.Set "page_number_flag" true }}
						{{ end }}
						<!-- Middle pages. -->
						{{ else }}
						{{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
						{{ $.Scratch.Set "page_number_flag" true }}
						{{ end }}
						{{ end }}
						<!-- Simple page numbers. -->
						{{ else }}
						{{ $.Scratch.Set "page_number_flag" true }}
						{{ end }}
						<!-- Output page numbers. -->
						{{ if eq ($.Scratch.Get "page_number_flag") true }}
						<li class="{{ if eq . $paginator }} active {{ end }}">
							<a href="{{ .URL }}">
								{{ .PageNumber }}
							</a>
						</li>
						{{ end }}
						{{ end }}
						<!-- Next page. -->
						{{ if $paginator.HasNext }}
						<li>
							<a href="{{ $paginator.Next.URL }}">{{ i18n "page_next" }}</a>
						</li>
						{{ end }}
					</ul>
				</nav>
				{{ end }}
      </div>
      <div class="col-md-4">
        {{ partial "blog-sidebar.html" . }}
      </div>
    </div>
  </div>
</div>

{{ end }}
